﻿using DTcms.Common;
using System.Web.Mvc;

namespace DTcms.Web.Mvc.UI.Page
{
    public partial class category : BaseController
    {
        protected int category_id; //类别ID
        protected string call_index; //类别别名
        protected string redirect = string.Empty;//回传地址

        protected Model.article_category category_model = new Model.article_category(); //分类的实体
        /// <summary>
        /// 重写虚方法,此方法将在Init事件前执行
        /// </summary>
        public category(Model.site_channel site_model)
        {
            category_id = DTRequest.GetQueryInt("category_id");
            call_index = Utils.SafeXXS(DTRequest.GetQueryString("call_index"));

            BLL.article_category bll = new BLL.article_category();
            category_model.title = "所有类别";
            if (category_id > 0) //如果ID获取到，将使用ID
            {
                if (!bll.Exists(category_id))
                {
                    redirect = linkurl("error", "?msg=" + Utils.UrlEncode("类别不存在！"));
                    return;
                }
                category_model = bll.GetModel(category_id);
            }
            else if (!string.IsNullOrEmpty(call_index)) //否则检查设置的别名
            {
                if (!bll.Exists(call_index))
                {
                    redirect = linkurl("error", "?msg=" + Utils.UrlEncode("类别不存在！"));
                    return;
                }
                category_model = bll.GetModel(call_index);
                //赋值类别ID
                category_id = category_model.id;
            }
            //判断SEO标题
            if (string.IsNullOrEmpty(category_model.seo_title) || "" == category_model.seo_title)
            {
                category_model.seo_title = category_model.title;
            }
            //获取频道内容
            site_model = new BLL.site_channel().GetCaCheModel(category_model.channel_id);
        }
    }
}
